from typing import List, Optional
from sqlalchemy.orm import Session
from sqlalchemy import desc

from app.crud.base import CRUDBase
from app.models.question_set import QuestionSet, QuestionSetQuestion
from app.schemas.question_set import QuestionSetCreate, QuestionSetUpdate

class CRUDQuestionSet(CRUDBase[QuestionSet, QuestionSetCreate, QuestionSetUpdate]):
    def get_multi(
        self, db: Session, *, skip: int = 0, limit: int = 100
    ) -> List[QuestionSet]:
        return (
            db.query(self.model)
            .order_by(desc(self.model.created_at))
            .offset(skip)
            .limit(limit)
            .all()
        )

    def get_with_questions(
        self, db: Session, *, id: int
    ) -> Optional[QuestionSet]:
        return (
            db.query(self.model)
            .filter(self.model.id == id)
            .first()
        )

question_set = CRUDQuestionSet(QuestionSet) 